#:kivy 1.0

#:import Window kivy.core.window.Window
# #:import Color levin.guiTheme.ColorTheme
#:set row_font_size 12
#:import levinCommon levin.levinCommon
#:import guiCommon levin.guiCommon


#:set white [1., 1., 1., 1.]
#:set black [0., 0., 0., 1.]
#:set transparent [1., 1., 1., 0.] 

## Primary Color:

#:set redwine [0.533, 0.035, 0.024, 1.]  #   #880906 # redwine
## [0.400, 0.122, 0.114, 1.]  #   #661F1D
## [0.345, 0.016, 0.008, 1.]  #   #580402
## [0.769, 0.231, 0.216, 1.]  #   #C43B37
## [0.769, 0.373, 0.365, 1.]  #   #C45F5D
## # ----- secondary :
## [0.533, 0.259, 0.024, 1.]  #   #884206  # brown
## [0.400, 0.247, 0.114, 1.]  #   #663F1D
## [0.345, 0.165, 0.008, 1.]  #   #582A02
## [0.769, 0.471, 0.216, 1.]  #   #C47837
## [0.769, 0.549, 0.365, 1.]  #   #C48C5D
## # ----- complementary :
#:set purple [0.431, 0.020, 0.243, 1.]  #   #6E053E  #purple
#:set purple1 [0.322, 0.090, 0.220, 1.]  #   #521738
#:set purple2 [0.278, 0.008, 0.157, 1.]  #   #470228
#:set purple3 [0.718, 0.204, 0.482, 1.]  #   #B7347B
#:set purple4 [0.718, 0.341, 0.545, 1.]  #   #B7578B
## # ----- complementary :
## [0.020, 0.420, 0.043, 1.]  #   #056B0B # green
## [0.090, 0.314, 0.102, 1.]  #   #17501A
## [0.008, 0.275, 0.024, 1.]  #   #024606
## [0.200, 0.710, 0.235, 1.]  #   #33B53C
## [0.337, 0.710, 0.361, 1.]  #   #56B55C
## # -----

<BBorderedWidget>:
    canvas.before:        
        Color:
            rgba: self.border_color            
        Bezier:
            points: self.border_points(self.x ,self.y, self.width, self.height, 0)
        Line:
            points: self.border_points(self.x ,self.y, self.width, self.height, 1)
        Bezier:
            points: self.border_points(self.x ,self.y, self.width, self.height, 2)
        Line:
            points: self.border_points(self.x ,self.y, self.width, self.height, 3)
        Bezier:
            points: self.border_points(self.x ,self.y, self.width, self.height, 4)
        Line:
            points: self.border_points(self.x ,self.y, self.width, self.height, 5)
        Bezier:
            points: self.border_points(self.x ,self.y, self.width, self.height, 6)
        Line:
            points: self.border_points(self.x ,self.y, self.width, self.height, 7)

<Label>:
    color: redwine
    canvas.before:
        Color:
            rgba: white
        Rectangle:
            pos: self.pos
            size: self.size
<CompactLabel>:
    # recopy TreeViewLabel
    #width: self.texture_size[0] # can cause pbms when text==''
    maxHeight: 16
    height: max(self.texture_size[1], self.maxHeight)
    text_size: self.width, None
    color: redwine 
    background_color: 1,1,1,1
    #font_size: row_font_size
    ## canvas.before:
    ##     Color:
    ##         rgba: white
    ##     Rectangle:
    ##         pos: self.pos
    ##         size: self.size

<CompactButton>:
    maxHeight: 16
    height: max(self.texture_size[1], self.maxHeight)
    text_size: self.width, None
    color: redwine 
    background_color: white if self.state=='normal' else purple3
    background_normal: ''
    background_down: ''
    halign: 'center'

<CompactTextInput>:
    #height: min(self.line_height*2, self.height)
    height: self.line_height*1.5
    size_hint_y: None if not self.multiline else 1

<LeVinTreeLabel>:
##     # recopy TreeViewLabel
##     #width: self.texture_size[0]
    halign: 'left'
    height: max(self.texture_size[1], 32)
##    text_size: self.width, None
##     #bkg_color:  [1,1,1,1 ]
##     #color: redwine 
    font_size: row_font_size

    canvas.before:
        Color:
            rgba: self.bkg_color
        Rectangle:
            #id: 'rect'
            size: self.size
            pos: self.pos 

<VisibleWinesLabel>:
    size_hint: (1,None)
    halign: 'center'

<LeVinPopup>:
    title_color: redwine

<LeVinIconLabel>:
    bkg_color: [1,1,1,0]
    padding_y: 2
    padding_x: 2
    canvas:
        Clear
        Color:
            rgba: white # self.color
        Rectangle:
            size: (root.icon_size,root.icon_size)
            source: root.icon_src
            pos: (root.x+root.padding_x,root.y+root.padding_y) if self.text !='' else (root.center_x-root.icon_size/2, root.y+root.padding_y)
        Color:
            rgba: self.color
        Rectangle:
            texture: self.texture
            size: self.texture_size
            pos: int(self.center_x+ root.icon_size+2*self.padding_x  - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.+self.padding_y)

<LeVinCompactButton>:
    bkg_color: [1,1,1,1]
    padding_y: 2
    padding_x: 2
    maxHeight: 24
    canvas.before:
        Color:
            rgba: white # self.color
        Rectangle:
            pos: self.pos
            size: self.size
    canvas:
        Clear
        Color:
            rgba: white # self.color
        Rectangle:
            size: (root.icon_size,root.icon_size)
            source: root.icon_src
            pos: (root.x+root.padding_x,root.y+root.padding_y) if self.text !='' else (root.center_x-root.icon_size/2, root.y+root.padding_y)
        Color:
            rgba: self.color
        Rectangle:
            texture: self.texture
            size: self.texture_size
            pos: int(self.center_x+ root.icon_size+2*self.padding_x  - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.+self.padding_y)

   


    
<LeVinButton,LeVinToggleButton>:
    color: purple2
    height: max(self.texture_size[1]+2, 32)
    size_hint: (1,None)
    padding_x: 2
    padding_y: 2    
    #width: self.texture_size[0]+self.icon_size+3*self.padding_x
    #height: max(self.texture_size[1],self.icon_size)+2*self.padding_y
    #background_normal: 'icons/redemptybox_small.png'
    #background_normal: 'icons/redemptybox.png'
    #border: 66,66,66,66
    #border: 22,22,22,22

    canvas:
        Clear
        ## Color:
        ##     rgba: purple2
        ## Rectangle:
        ##     pos: self.pos
        ##     size: self.size
        ## Color:
        ##     rgba: white if  self.state == 'normal' else purple4
        ## Rectangle:
        ##     pos: (self.x+2, self.y+2)
        ##     size: (self.width-4, self.height-4)
        Color:
            rgba: 1,1,1,1
        BorderImage:
            #border: self.border
            border: 11,11,11,11
            #border: 66,66,66,66
            pos: self.pos
            size: self.size
            #source: self.background_normal if self.state == 'normal' else self.background_down
            source: 'icons/redemptybox_small2.png' if self.state == 'normal' else 'icons/redGreenbox_small2.png'
        Color:
            rgba: white #self.color
        #Image:
        Rectangle:
            size: (root.icon_size,root.icon_size) # see icon_size in LeVinIconProvider (binded to self.height)
            source: root.icon_src
            #pos: self.pos if self.text !='' else (root.center_x-root.icon_size/2, root.y)
            pos: (root.center_x - (root.icon_size+root.texture_size[0])/2 -self.padding_x, root.y+root.padding_y)   if self.text !=''  else (root.center_x-root.icon_size/2, root.y+root.padding_y)
        Color:
            rgba: self.color
        Rectangle:
            texture: self.texture
            size: self.texture_size
            pos: root.center_x - (-root.icon_size+root.texture_size[0])/2 +2 -self.padding_x,  int(self.center_y - self.texture_size[1] / 2.+self.padding_y)
            #pos: int(root.center_x+ root.icon_size/2. +1- self.padding_x  - (self.texture_size[0] / 2.) ),


<LeVinTabLayout>:
	content_obj: content_obj
	header_obj: header_obj
	orientation: 'vertical'
	
	GridLayout:
		id:header_obj
		rows:1
		size_hint: (1, 0.1)
        
	BoxLayout:
		id: content_obj
		size_hint: (1, 0.9)
        canvas:
            Clear
        ## canvas:
        ##     Color:
        ##         rgba: purple4
        ##     Rectangle:
        ##         pos: (self.x, self.top-2)
        ##         size: (self.width, 2)
        ##     Color:
        ##         rgba: white
        ##     Rectangle:
        ##         pos: (root.selected_button.x+2 if root.selected_button else 0, self.top-2)
        ##         size: (root.selected_button.width-4 if root.selected_button else 0, 2)

<LeVinTabButton>:
    size_hint: (1,1)    
    bold: self.state != 'normal'
    font_size: row_font_size if self.state == 'normal' else row_font_size+6
    color: purple4 if self.state == 'normal' else purple2
    decoration_height: 10
    canvas:
        Clear
        Color:
            rgba: white # self.color
        Rectangle:
            # was Image
            size: (root.icon_size,root.icon_size)
            source: root.icon_src
            pos: self.pos if self.text !='' else (root.center_x-root.icon_size/2, root.y)
        Color:
            rgba: self.color
        Rectangle:
            texture: self.texture
            size: self.texture_size
            pos: int(self.center_x+ root.icon_size+2*self.padding_x  - self.texture_size[0] / 2.), int(self.center_y - self.texture_size[1] / 2.+self.padding_y)
        Color:
            rgba: purple2 if self.state != 'normal' else  purple4 #transparent
        Rectangle:
            source: "icons/underline_gradient.png" 
            pos: (self.x, self.y+ self.decoration_height/3) if self.state != 'normal' else  (self.x+self.width*0.25, self.y+ self.decoration_height)
            size: (self.width, self.decoration_height) if self.state != 'normal' else (self.width*0.5, self.decoration_height*0.5)

            






<LeVinButtonBar>:
    on_children: self._trigger_resize_to_children()
    #height: max(w.height for w in self.children) if self.tt(self.children) else self.tt(32)

    
    
<ComboBox>:
    height: max( c.height for c in self.children) if self.children else 32

<DropDown>:
    canvas.before:
        #Clear --> don't ! it generate warnings and freezes
        Color:
            rgba: redwine
        Rectangle:
            pos: self.pos
            size: self.size 

<LeVinCombo>:
    unlocalize: False
    textInputClass: guiCommon.CompactTextInput
    entryWidClass: guiCommon.CompactButton
    internSpacing: 2
    padding: 2
    
<LeVinSpinBox>:
    background_color: redwine
    up_button_icon_src: "icons/arrow_down.png"
    #height: self.txtinput.line_height*2

<TreeViewWithHeaderBase>:
    resize_line_color: redwine


<LeVinRegionLabel>:
    bold: True

<LeVinCountryLabel>:
    bold: True
    
<TreeViewNode>:
    canvas.before:
        Clear
        Color:
            rgba: 1, 1, 1, int(not self.is_leaf)
        Rectangle:
            source: 'data/images/tree_%s.png' % ('opened' if self.is_open else 'closed')
            size: 16, 16
            pos: self.x - 20, self.center_y - 8
    canvas.after:
        Clear
        Color:
            rgba: self.color_selected if self.is_selected else self.odd_color 
        Rectangle:
            pos: [self.treeview.internal_x(self.x), self.y] # the self.x arg is here only to bind this pos to self...
            size: [self.treeview.internal_width(self.width), self.height] # if self.parent else [1, 1]
        Color:
            rgba: .5, .5, .5, .2
        Line:
            points: [self.treeview.internal_x(self.x), self.y, self.treeview.internal_right(self.width), self.y] # arguments are dummy (see above comment)

<Slider>:
    width: 16
    canvas:
        Clear
        Color:
            rgba: redwine        
        Rectangle:
            pos: (self.x, self.value_pos[1] -15)
            size: (self.width, 30)
            source: 'icons/redfullbox.png'

<LeVinAlertModal>:
    background: levinCommon.iconPath("whiteredfullbox.png")
    border: [11,]*4
    cancelB: _cancelB
    validB: _validB
    padding: 4
    auto_dismiss: False
    StackLayout:
        orientation: 'bt-lr'
        LeVinButton:
            id: _cancelB
            size_hint:(1,0.2)
            text: root.cancelText
        LeVinButton:
            id: _validB
            size_hint:(1,0.2)
            text: root.validText
<CameraCapture>:
    background: levinCommon.iconPath("whiteredfullbox.png")
    size: Window.size
    camera: _cam
    doneB: _doneB
    BoxLayout:
        orientation: 'vertical'
        Camera:
            #size_hint: 1,None
            resolution: Window.width -1, Window.height-32
            id: _cam
        BoxLayout:
            oprientation: 'horizontal'
            size_hint: (1, None)
            height: 32
            LeVinButton:
                text: _("Stop") if _cam.play else _("Continue")
                on_press: _cam.play= not _cam.play
            LeVinButton:
                id:_doneB
                text: _("Ok")
                on_press: root.done()

<LeVinAlert>:
    #_container: container
    #cancelB: _cancelB
    #validB: _validB
    separator_color: purple2
    title_color: purple2 # added
    ## canvas:
    ##     Clear
    ##     Color:
    ##         rgba: root.background_color[:3] + [root.background_color[-1] * self._anim_alpha]
    ##     Rectangle:
    ##         size: self._window.size if self._window else (0, 0)

    ##     Color:
    ##         rgb: 0, 0, 0
    ##     Rectangle:
    ##         pos:self.pos
    ##         size: self.size
    ##     Color:
    ##         rgb: 1,1,1
    ##     Rectangle:
    ##         pos: (self.x+self._border_size,self.y+self._border_size)
    ##         size: (self.width-2*self._border_size, self.height-2*self._border_size)

    ## GridLayout:
    ##     background_color: white
    ##     padding: 12
    ##     cols: 1
    ##     size_hint: None, None
    ##     pos: root.pos
    ##     size: root.size

    ##     Label:
    ##         text: root.title
    ##         size_hint_y: None
    ##         height: self.texture_size[1] + 16
    ##         text_size: self.width - 16, None
    ##         color:redwine
            
    ##     Widget:
    ##         size_hint_y: None
    ##         height: 4
    ##         canvas:
    ##             Color:
    ##                 rgba: root.separator_color
    ##             Rectangle:
    ##                 pos: self.x, self.y + root.separator_height / 2.
    ##                 size: self.width, root.separator_height




## <LeVinAlertContent>:
##     orientation: 'vertical'
##     Label:
##         text: root.alertText
##         color: redwine
##     LeVinButton:
##         id: _cancelB
##         text: root.cancelText
##     LeVinButton:
##         id: _validB
##         text: root.validText
    
